﻿using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TextTemplating.VSHost;
using System.IO;

namespace Demo.SharePointTopNavDSL.CodeGenerator
{
    [Guid("32BF3242-BB5A-4e5f-A457-3ADFA46A4549")]
    [ProvideCodeGenerator(typeof(PowerShellScriptGenerator),
        "TopNavPowerShellScriptGenerator", 
        "A tool that generates PowerShell script based on the TopNav DSL", true)]
    
    public class PowerShellScriptGenerator : TemplatedCodeGenerator
    {
        protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
        {            
            FileInfo fi = new FileInfo(inputFileName);
            StreamReader sr = new StreamReader(
                GetType().Assembly.GetManifestResourceStream("Demo.SharePointTopNavDSL.Resources.PowerShell.template"));

            inputFileContent = sr.ReadToEnd();
            inputFileContent = inputFileContent.Replace("%MODEL_FILE_NAME%", fi.Name);
            inputFileContent = inputFileContent.Replace("%MODEL_DIAGRAM_FILE_NAME%", fi.FullName + ".diagram");
            byte[] data = base.GenerateCode(inputFileName, inputFileContent);
            return data;
        }
    }
}
